function [model]=E_step_fdebug(model, data, MAXESTEPITER, MaxFun, maxvalue, countVEM)

% global model;
% global n;

MINDIFF   = 0.005;
conv_diff = 100000000;
count     = 0;
N         = model.N;

value0    = maxvalue;

while(conv_diff>MINDIFF && count<MAXESTEPITER)

 disp('count from E-step');
 count = count+1
 
 for n=1:N
  n
  model=update_phi_1(model,data,n);
  value1 = cal_likelihood(model, data);
  
  if (compareval(value1, maxvalue))
        maxvalue = value1;
        %disp('correct');
  else
        disp('Incorrect');
        keyboard;
  end
  
  
  %model=update_phi_2(model,data,n);
%   value2 = cal_likelihood(model, data);
%   
%   
%   if (compareval(value2, maxvalue))
%         maxvalue = value2;
%         %disp('correct');
%   else
%         disp('Incorrect');
%         keyboard;
%   end
    
  model=update_alpha_1(model,n, MaxFun);
  value3 = cal_likelihood(model, data);
  
  
  if (compareval(value3, maxvalue))
        maxvalue = value3;
        %disp('correct');
  else
        disp('Incorrect');
        keyboard;
  end
  
  %model=update_alpha_2(model,n, MaxFun);
%   value4 = cal_likelihood(model, data);
%   
%   if (compareval(value4, maxvalue))
%         maxvalue = value4;
%         disp('correct');
%   else
%         disp('Incorrect');
%         keyboard;
%   end
  
  model=update_sigma_1(model,n, MaxFun);
  value5 = cal_likelihood(model, data);
  
  if (compareval(value5, maxvalue))
        maxvalue = value5;
        %disp('correct');
  else
        disp('Incorrect');
        keyboard;
  end
  
  %model=update_sigma_2(model,n, MaxFun);
%   value6 = cal_likelihood(model, data);
%   
%   if (compareval(value6, maxvalue))
%         maxvalue = value6;
%         disp('correct');
%   else
%         disp('Incorrect');
%         keyboard;
%   end
  
  model=update_zeta_1(model, n);   
  value7 = cal_likelihood(model, data);
 
 
  if (compareval(value7, maxvalue))
        maxvalue = value7;
        %disp('correct');
  else
        disp('Incorrect');
        keyboard;
  end
 
  %model=update_zeta_2(model, n);
  value8 = cal_likelihood(model, data);
 
  if (compareval(value8, maxvalue))
        maxvalue = value8;
        disp('correct');
  else
        disp('Incorrect');
        keyboard;
  end

 conv_diff=abs(value0-value8)/abs(value0);
 value0=value8;
 
  
 end %
 
 
 %value2=value1;

end
   
end
    
